package com.airnewslinkosky.ticket.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.airnewslinkosky.ticket.R;

@SuppressWarnings("unchecked")
public class CityListViewAdapter extends ArrayAdapter  {

	LayoutInflater layoutInflater ;
	List<Map<String, Object>> items;
	Context context;
	Object[] objects;

	@SuppressWarnings("unchecked")
	public CityListViewAdapter(Context context, int resource,Object[] objects) {
		super(context, resource, objects);
		this.context = context;
		this.objects = objects;
		System.out.println("CityListViewAdapter");
		layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		  ViewHolder holder; 
		  LinearLayout cityLayout = null;
		  //得到自己定义的List的界面
		  if (cityLayout == null) { 
			  cityLayout =(LinearLayout) this.layoutInflater.inflate(R.layout.city_row, null); 
			  holder = new ViewHolder(); 
			  holder.cityInfo = (TextView) cityLayout.findViewById(R.id.city_info); 
			  cityLayout.setTag(holder); 
		  } else {
			  holder = (ViewHolder) cityLayout.getTag(); 
		  }
		  if(this.objects[position].toString().equals("热点")){
				cityLayout.setBackgroundResource(R.drawable.blue_bg2);
				holder.cityInfo.setText("热点城市");
				holder.cityInfo.setTextAppearance(this.context, R.style.text_16_white_b);
		 } else if(this.objects[position].toString().length() == 1){
			cityLayout.setBackgroundResource(R.drawable.blue_bg2);
//			LinearLayout.LayoutParams parms =  new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
//			parms.height = 31;
//			cityLayout.setLayoutParams(parms);
			holder.cityInfo.setText(this.objects[position].toString());
			holder.cityInfo.setTextAppearance(this.context, R.style.text_16_white_b);
			cityLayout.invalidate();
		 } else {
			 holder.cityInfo.setText(this.objects[position].toString());
		 }
		 return cityLayout;

	}
	
	static class ViewHolder { 
		TextView cityInfo;
	}

}
